import java.util.ArrayList;
import java.util.List;
import java.util.TreeSet;

public class Solution855 {

    TreeSet<Integer> set=new TreeSet<>();
    int n;

    public Solution855(int n) {
        this.n=n;
    }

    public int seat() {
        if (set.size()==0){
            set.add(0);
            return 0;
        }else{
            int max=0,pos=-1;
            List<Integer> list=new ArrayList<>(set);
            if (list.get(0)>max){
                max=list.get(0);
                pos=0;
            }
            for (int i=1;i<list.size();i++){
                if ((list.get(i)-list.get(i-1))/2>max){
                    max=(list.get(i)-list.get(i-1))/2;
                    pos=list.get(i-1)+max;
                }
            }

            if (n-1-list.get(list.size()-1)>max){
                pos=n-1;
            }
            set.add(pos);
            return pos;
        }
    }

    public void leave(int p) {
        set.remove(p);
    }

    public static void main(String[] args) {
        Solution855 solution855=new Solution855(10);
        System.out.println(solution855.seat());
        System.out.println(solution855.seat());
        System.out.println(solution855.seat());
        System.out.println(solution855.seat());
        solution855.leave(4);
        System.out.println(solution855.seat());
    }
}
